﻿using AutoMapper;
using B.S.Filtration.Domain;
using B.S.Filtration.ErrorCode;
using B.S.Filtration.Read.Api.Application.Command.PowerCommand;
using MediatR;
using SqlSugar;
using static NPOI.HSSF.Util.HSSFColor;

namespace B.S.Filtration.Read.Api.Application.CommandHander.PowerCommandHander
{
    public class ShowPowerCommandHander:IRequestHandler<ShowPowerCommand,APIResult<List<Power>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public ShowPowerCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<APIResult<List<Power>>> Handle(ShowPowerCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Power>> result = new APIResult<List<Power>>();

            var list = await db.Queryable<Power>()
                                .Where(x => x.Del == false && x.PowerId == request.PowerId)
                                .ToListAsync();

            result.data = list;

            result.code = APIResultCode.success;
            result.msg = "查询成功";

            return await Task.FromResult(result);
        }
    }
}
